package com.bk.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bk.entity.MenuInfo;
import com.bk.service.MenuRoleService;
import com.bk.util.ReturnUtil;

/** 权限菜单 */
@RestController
public class MenuRoleController {

	@Autowired /** 角色菜单服务 */
	private MenuRoleService menuRoleService;

	@GetMapping("/getRoleMenuList") /** 获取一级菜单 */
	public ReturnUtil<MenuInfo> getRoleMenuList() {

		List<MenuInfo> roleMenuList = menuRoleService.getRoleMenuList();

		return new ReturnUtil<MenuInfo>(200, "获得权限的一级角色菜单", roleMenuList);

	}

	@PostMapping("/getTwoRoleMenuList") /** 获取二级菜单 */
	public ReturnUtil<MenuInfo> getTwoRoleMenuList(@RequestParam("parentId") int parentId) {
		List<MenuInfo> roleTwoMenuList = menuRoleService.getTwoRoleMenuList(parentId);
		return new ReturnUtil<MenuInfo>(200, "获得二级权限的角色菜单", roleTwoMenuList);
	}

	@PostMapping("/getHaveRoleMenuList/{roleId}") /** 获取已授权菜单 */
	public ReturnUtil<MenuInfo> getHaveRoleMenuList(@PathVariable("roleId") int roleId) {

		List<MenuInfo> roleMenuList = menuRoleService.getHaveRoleMenuList(roleId);
		return new ReturnUtil<MenuInfo>(200, "获得权限的一级角色菜单", roleMenuList);

	}

	@PostMapping("/getAllRoleUnMenuList/{roleId}") /** 获取未授权菜单 */
	public ReturnUtil<MenuInfo> getAllRoleUnMenuList(@PathVariable("roleId") int roleId) {

		ReturnUtil<MenuInfo> ru = menuRoleService.getAllRoleUnMenuList(roleId);
		return ru;
	}

	@PostMapping("/removeAutority") /** 移除菜单权限 */
	public ReturnUtil<MenuInfo> removeAutority(@RequestParam("menuAuths") String menuAuths,@RequestParam("roleId") String roleId) {
 
		ReturnUtil<MenuInfo> ru = menuRoleService.removeAutority(menuAuths,roleId);
		return ru;
	}
	@PostMapping("/addmenuAutority")/**添加菜单权限*/
	public ReturnUtil<MenuInfo> addmenuAutority(@RequestParam("menuAuths") String menuAuths,@RequestParam("roleId") String roleId){
		ReturnUtil<MenuInfo> ru = menuRoleService.addmenuAutority(menuAuths,roleId); 
		return ru;
	}
	
	@PostMapping("/getStatus")/**获取当前会话状态*/
	public ReturnUtil<MenuInfo> getStatus(){
		ReturnUtil<MenuInfo> ru = menuRoleService.getStatus(); 
		return ru;
	}
}
